var Ellipse = AbstractPrimitive.extend({
    init: function(origin, xRadius, yRadius){
        this._origin = origin;
        this._xRadius = xRadius;
        this._yRadius = yRadius;
    },
    setOrigin: function(origin){
        this._origin = origin;
    },
    getOrigin: function(){
        return this._origin;
    },
    getCenter: function(){
        return this.getOrigin();
    },
    setXRadius: function(xRadius){
        this._xRadius = xRadius;
    },
    getXRadius: function(){
        return this._xRadius;
    },
    setYRadius: function(yRadius){
        this._yRadius = yRadius;
    },
    getYRadius: function(){
        return this._yRadius;
    },
    getBox: function(){
        return new Rectangle(new Point(this._origin.getX() - this.getXRadius(), this._origin.getY() - this.getYRadius()),2*this.getXRadius(),2*this.getYRadius());
    },
    getIntersectionFromCenterToPoint: function(point){
        var deltaX = point.getX() - this._origin.getX(),
            deltaY = point.getY() - this._origin.getY();

        if (deltaX == 0 || deltaY == 0){
            return this.getBox().getIntersectionFromCenterToPoint(point);
        }

        var m = deltaY / deltaX,
            mSquared = m * m,
            xRadiusSquared = this.getXRadius() * this.getXRadius(),
            yRadiusSquared = this.getYRadius() * this.getYRadius(),
            x = Math.sqrt(1 / ((1 / xRadiusSquared) + (mSquared / yRadiusSquared)));

        if (deltaX < 0){
            x = -x;
        }


        var y = m * x;
        return new Point(this._origin.getX() + x, this._origin.getY() + y);
    }
});